package cn.ivast.recyclerviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.ivast.recyclerviewtest.adapter.StickyAdapter;
import cn.ivast.recyclerviewtest.bean.StickyBean;
import cn.ivast.recyclerviewtest.decoration.StickyDecoration;

public class StickyActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<StickyBean> datas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sticky);

        recyclerView = findViewById(R.id.recyclerView);

        datas = new ArrayList<>();
        datas.add(new StickyBean("湖南", "长沙"));
        datas.add(new StickyBean("湖南", "邵阳"));
        datas.add(new StickyBean("湖南", "怀化"));
        datas.add(new StickyBean("湖南", "衡阳"));
        datas.add(new StickyBean("湖南", "益阳"));
        datas.add(new StickyBean("湖南", "岳阳"));
        datas.add(new StickyBean("湖南", "岳阳32"));
        datas.add(new StickyBean("湖南", "岳阳3"));
        datas.add(new StickyBean("湖南", "岳阳4"));
        datas.add(new StickyBean("湖南", "岳阳42"));
        datas.add(new StickyBean("湖南", "岳阳44"));
        datas.add(new StickyBean("湖南", "岳阳45"));

        datas.add(new StickyBean("安徽", "合肥"));
        datas.add(new StickyBean("安徽", "芜湖"));
        datas.add(new StickyBean("安徽", "蚌埠"));
        datas.add(new StickyBean("安徽", "蚌埠2"));
        datas.add(new StickyBean("安徽", "蚌埠3"));
        datas.add(new StickyBean("安徽", "蚌埠4"));

        datas.add(new StickyBean("浙江", "杭州"));
        datas.add(new StickyBean("浙江", "宁波"));
        datas.add(new StickyBean("浙江", "温州"));
        datas.add(new StickyBean("浙江", "嘉兴"));
        datas.add(new StickyBean("浙江", "绍兴"));
        datas.add(new StickyBean("浙江", "金华"));
        datas.add(new StickyBean("浙江", "湖州"));
        datas.add(new StickyBean("浙江", "舟山2"));
        datas.add(new StickyBean("浙江", "舟山3"));
        datas.add(new StickyBean("浙江", "舟山4"));
        datas.add(new StickyBean("浙江", "舟山5"));
        datas.add(new StickyBean("浙江", "舟山63"));
        datas.add(new StickyBean("浙江", "舟山46"));
        datas.add(new StickyBean("浙江", "舟山65"));
        datas.add(new StickyBean("浙江", "舟山66"));
        datas.add(new StickyBean("浙江", "舟山67"));
        datas.add(new StickyBean("浙江", "舟山61"));

        StickyAdapter adapter = new StickyAdapter(recyclerView);
        adapter.setData(datas);
        LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        StickyDecoration stickyDecoration = new StickyDecoration();
        stickyDecoration.setListener(new StickyDecoration.GroupListener() {
            @Override
            public String getGroupName(int position) {
                return datas.get(position).getProvinceName();
            }
        });
        recyclerView.addItemDecoration(stickyDecoration);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
    }
}
